import SJGReplaceGroup = require('./../replace/SJGReplaceGroup');
import SJGReplaceItemBase = require('./../replace/SJGReplaceItemBase');
import GCJ_CLASS_TYPE=require('./../../common/GCJ_CLASS_TYPE');
import Parser=require('./Parser');
export  = ParserOfUserReplaces;

/**
 *
 * @author 
 *
 */
class ParserOfUserReplaces {
	public constructor() {
	}
    
    
    // 从一个用户传递的replaces json对象中，解析出对应RSJGReplaceGroup
    public static  fromUnknownJson (jsonObj, versionId, globalData?):any{
        if(!jsonObj){
            return null;
        }
        var replaceGrp=new SJGReplaceGroup(globalData);
        replaceGrp.kind=jsonObj.kind;
        replaceGrp.min=jsonObj.min;
        replaceGrp.max=jsonObj.max;
        replaceGrp.id=jsonObj.id;
        
        for(var i in jsonObj.value){
            var obj=jsonObj.value[i];
            // 1titleGroup/2textGroup/3imageGroup/4chartGroup/5tableGroup/6imageTextGroup/
            var item: SJGReplaceItemBase=null;
            if(jsonObj.kind==SJGReplaceGroup.TITLEGROUP) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemText](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.TEXTGROUP){ 
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemText](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.IMAGEGROUP){
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemImage](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.CHARTGROUP) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemChart](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.TABLEGROUP) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemTable](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.IMAGETEXTGROUP) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGSubGroupImageTextOld](globalData);
            } else if(jsonObj.kind == SJGReplaceGroup.TEXTGROUP2) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGSubGroupText](globalData);
            } else if(jsonObj.kind == SJGReplaceGroup.IMAGETEXTGROUP2) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGSubGroupImageText](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.COMMENTGROUP){
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemText](globalData);
            } else if(jsonObj.kind==SJGReplaceGroup.GRAPHGROUP) {
                item=new Parser.lib[GCJ_CLASS_TYPE.CLASS_TYPE_SJGReplaceItemGraph](globalData);
            }
            if(item!=null) {
                item.fromJson(obj,versionId);
                replaceGrp.value.push(item);
            }
        }
        
        return replaceGrp;
    }
    
//SJG_MARK_APPEND--------------------


}//SJG_M